package cn.ljy.uem.dao;

import cn.ljy.uem.model.SchoolTeacher;
import cn.ljy.uem.model.SchoolTeachingTaskStudent;
import cn.ljy.uem.model.SchoolTeachingTaskTeacher;
import org.apache.ibatis.annotations.*;

import java.io.Serializable;
import java.util.List;

/**
 * @description 教学任务教师的数据层操作类
 * @author 廖振豪
 * @date 2022-7-21
 */

@Mapper
public interface SchoolTeachingTaskTeacherMapper{

    /**
     * 根据指定教学任务包含的教师集合
     * @param teachingTaskId
     * @return
     */
    List<SchoolTeacher> findAllTeacherByTeachingTaskId(Integer teachingTaskId);

    /**
     * 根据指定教学任务获取拥有的所有教师数量
     * @param teachingTaskId
     * @return
     */
    @Select("select count(1) from school_teachingtask_teacher where teachingtask_id = #{teachingTaskId}")
    int countAllTeacherByTeachingTaskId(Integer teachingTaskId);

    /**
     * 根据指定教学任务获取拥有的所有教师类型数量
     * @param teachingTaskId type
     * @return
     */
    @Select("select count(1) from school_teachingtask_teacher where teachingtask_id = #{teachingTaskId} and `type`=#{type}")
    int countByUserIdAndRoleId(Serializable teachingTaskId, Serializable type);

    /**
     * 查找单个教师 findById
     * @param teachingTaskId
     * @param teacherId
     * @return
     */
    SchoolTeachingTaskTeacher findByTeachingTaskIdAndTeacherId(Serializable teachingTaskId, Serializable teacherId);

    /**
     * 插入教学任务和教师及教师类型的关系
     * @param teachingTaskId
     * @param teacherId
     * @param type
     * @return
     */
    @Insert("insert into school_teachingtask_teacher(teachingtask_id,teacher_id,type,create_time) values(#{teachingTaskId},#{teacherId},#{type},now())")
    int save(Serializable teachingTaskId, Serializable teacherId,Serializable type);

    /**
     * 修改教师类型
     * @return
     */
    @Update("update school_teachingtask_teacher set type=#{type},update_time=now() where teachingtask_id=#{teachingTaskId} and teacher_id=#{teacherId}")
    void update(SchoolTeachingTaskTeacher teacher);

    /**
     * 移除教学任务和教师的关系
     * @param teachingTaskId
     * @param teacherId
     * @return
     */
    @Delete("delete from school_teachingtask_teacher where teachingtask_id=#{teachingTaskId} and teacher_id=#{teacherId}")
    int delete(Serializable teachingTaskId, Serializable teacherId);

    /**
     * 获取表中符合条件的所有记录
     * 说明：如果查询条件为null，则表示查询所有记录
     * @return
     */
    List<SchoolTeachingTaskTeacher> findAll(@Param(value = "objectQuery")Object objectQuery);

    /**
     * 获取符合查询条件的记录数，一般与query配合使用
     * @param objectQuery 查询条件类
     * @return 符合查询条件的记录数
     */
    int count(@Param(value = "objectQuery")Object objectQuery);

    /**
     * 读取部分记录，一般配合业务层分页方法展示
     * @param offset 第一条记录索引（从0开始）
     * @param length 显示记录个数（指从第一条记录开始，显示第N条）
     * @param objectQuery 查询条件类
     * @return 符合查询条件的记录
     */
    List<SchoolTeachingTaskTeacher> find(@Param(value = "offset") final int offset, @Param(value = "length") final int length, @Param(value = "objectQuery")Object objectQuery);

    /**
     * 删除该教学任务对应的教学任务与教师的关系  按照教学任务Id删除整个教学任务教师
     * @param teachingTaskIds 教学任务集合
     */
    int deleteByTeachingTaskIds(java.io.Serializable[] teachingTaskIds);
}